{{include file="header.html"}}
<div class="header loginhead">
	<div class="nav">
	    <div class="search return"><a href="javascript:history.go(-1);"></a></div>
	    <div class="title">注册</div>
	    <div class="right">
	        <a href="index.php?app=Login">登录</a>
	    </div>
	</div>
</div>
<div class="container login">
	<div class="loginbox">
		<form name="myform" method="post">
			<div class="login_wrap tel">
				<span class="icon">
					<img src="{{$smarty.const.__APP__}}images/tel.png" alt="">
				</span>
				<div class="input_text">
					<input type="text" placeholder="请输入手机号" id="tel" name="tel">
				</div>
				<span class="verifybtn" id="sms-btn">获取验证码</span>
			</div>
			<div class="login_wrap ver">
				<span class="icon">
					<img src="{{$smarty.const.__APP__}}images/verify.png" alt="">
				</span>
				<div class="input_text">
					<input type="text" placeholder="请输入验证码" id="ver" name="code">
				</div>
			</div>
			<div class="login_wrap" style='margin-left:-0.20rem'>
				<span class="icon">
					<img src="{{$smarty.const.__APP__}}images/pw.png" alt="">
				</span>
				<div class="input_text">
					<input name="password" type="password" placeholder="请设置6位以上的登录密码">
				</div>
			</div>	
			<div class="login_wrap" style='margin-left:-0.20rem'>
				<span class="icon">
					<img src="{{$smarty.const.__APP__}}images/pw.png" alt="">
				</span>
				<div class="input_text">
					<input name="password2" type="password" placeholder="请再次填写密码">
				</div>
			</div>	
			<!-- <div class="agree">
				<input type="checkbox" id="agreecheck"  checked="checked">
				<label class="login_lb" for="agreecheck"><span>我已阅读并同意</span>《一元运购互助购物协议》</label>
			</div> -->
			<div class="loginbtn">
				<a href="javascript:" class="btn-login">注册</a>
			</div>
			
		</form>	
	</div>
</div>
<style>
.btn-retransmit-disabled {
	cursor:default;
	color:#bdbdbd
}	
</style>
<script type="text/javascript">

	//点击获取号码
	$(".verifybtn").click(function(){
		if($('#sms-btn').hasClass("btn-retransmit-disabled")) return false;
		dysms();
	})

	//获取验证码
	var dysms = function(){
		//获取号码
		var tel = $("#tel").val();
		//异步提交
		$.post('{{"index.php?app=Login&register"|URL}}',{'tel':tel},function(result){
	        if(result.statusCode=='200'){
	        	set_time(1);
	        	ui.success('短信发送成功!');
	        	setCookie('sms',result.message,'5');
	        	$('#sms-btn').addClass("btn-retransmit-disabled");
	        } 
	        else ui.error(result.message);
	    },'json');
	}

	$(function(){
		$('.btn-login').click(function(){
			// if(!$('#agreecheck').attr('checked')){
		 //    	ui.alert('必须接受《一元运购互助购物协议》才能注册!');
		 //    	return false;
			// }
			if(!$('#sms-btn').hasClass("btn-retransmit-disabled")){
				ui.error('请获取验证码!');
				return false;
			} 
			//获取短信验证码
			var sms = getCookie("sms");
			//获取输入的验证码
			var code = $("#ver").val();
			//验证码正确与否
			if(sms == code && sms != ''){
				var params = $("form").serialize();
				$.post('{{"index.php?app=Login&verify"|URL}}',params,function(result){
			        if(result.statusCode=='200'){
			        	ui.success(result.message);
			        	setTimeout(function(){
							location.href='{{"index.php?app=Login"|URL}}';
						},1000);
			        }else ui.error(result.message);
			    },'json');
			}else if(!$("#tel").val()){
				ui.error('手机号码错误!');
				return false;
			}else if(!$('#sms-btn').hasClass("btn-retransmit-disabled")){
				ui.error('请获取验证码!');
				return false;
			}else{
				ui.error('验证码错误!');
				$("#ver").val("");
				return false;
			}
		});
	});
</script>
<script type="text/javascript">
	var vod_show;
	function show_time() 
	{
		 var nowtime = new Date(); 
		 var leftsecond=parseInt((document.endtime-nowtime.getTime())/1000); 
		 s=parseInt(leftsecond); 
		 var c=new Date();
		 $('#sms-btn').html(" 已发送（"+s+"）");
		 if(leftsecond<=0){ 
			$('#sms-btn').removeClass("btn-retransmit-disabled");
		 	$('#sms-btn').css("cursor",'pointer');
		 	$('#sms-btn').html("获取短信验证码");
		 	clearInterval(vod_show); 
		 } 
	}

	//设置倒计时(分钟)
	function set_time(min){
		vod_show=setInterval(show_time,100); 	
		document.endtime = new Date();
		document.endtime = document.endtime.getTime();
		document.endtime = parseInt(document.endtime)+(min*60*1000);
	}
</script>
{{include file="footer.html"}}